import 'package:cat_eye/base/base_refresh_state.dart';
import 'package:cat_eye/base/base_view_model.dart';
import 'package:cat_eye/bean/find_class_if_coation_bean.dart';
import 'package:cat_eye/root_page/home_page/hom_video_page_widget.dart';
import 'package:cat_eye/root_page/home_page/video_details_widget.dart';
import 'package:cat_eye/util/util.dart';
import 'package:cat_eye/view_model/find_view_model/find_classification_details_view_model.dart';
import 'package:flutter/material.dart';

/*
* @Package: root_page.find_page
* @ClassName: find_classification_details_idget
* @Author: szj
* @CreateDate: 8/2/21 4:54 PM
* TODO 发现-分类详情
*/
class FindClassificationDetailsWidget extends StatefulWidget {
  final FindClassIfCoationBean item;

  const FindClassificationDetailsWidget(this.item, {Key key}) : super(key: key);

  @override
  _FindClassificationDetailsWidgetState createState() =>
      _FindClassificationDetailsWidgetState();
}

class _FindClassificationDetailsWidgetState extends BaseRefreshState<
    FindClassificationDetailsWidget, FindClassificationDetailsViewModel> {
  @override
  FindClassificationDetailsViewModel get buildViewModel =>
      FindClassificationDetailsViewModel(widget.item.id);

  @override
  Widget buildWidget(
      BuildContext context, FindClassificationDetailsViewModel model) {
    //TODO 参考我之前写的文档:[https://blog.csdn.net/weixin_44819566/article/details/111579338]

    return Scaffold(
      body: CustomScrollView(
        //缓存条目
        cacheExtent: 0,
        slivers: [
          //顶部可滑动appbar
          buildSliverAppBar(),

          //底部ListView
          buildSliverList(model, context),
        ],
      ),
    );
  }

  Widget buildSliverList(FindClassificationDetailsViewModel model, context) {
    return SliverList(
      delegate: SliverChildBuilderDelegate((context, index) {
        return InkWell(
            onTap: () {
              Navigator.push(
                  context,
                  router(
                      widget: VideoDetailsWidget(
                          data: model.itemList[index].data)));
            },
            child: HomeVideoPageWidget(video: model.itemList[index]));
      }, childCount: model.itemList.length),
    );
  }

  Widget buildSliverAppBar() {
    return SliverAppBar(
      //滑动高度
      expandedHeight: 220,

      //AppBar是否在状态栏下面
      primary: true,

      backgroundColor: Colors.black26,

      //当snap = true时 这个参数必须为true!!!
      floating: false,

      //AppBar固定
      pinned: true,

      //AppBar跟随手指滑动而滑动  floating必须为true才可以使用
      snap: false,

      flexibleSpace: FlexibleSpaceBar(
        background: cacheImage(widget.item.headerImage),
        collapseMode: CollapseMode.pin,
        //标题居中
        centerTitle: true,
        title: Text(
          widget.item.name,
        ),
      ),
    );
  }
}
